{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['data_batch_1', 'data_batch_2', 'data_batch_5', 'data_batch_4', 'data_batch_3', 'batches.meta', 'readme.html', 'test_batch']\n"
     ]
    }
   ],
   "source": [
    "import pickle\n",
    "import numpy as np\n",
    "import os\n",
    "\n",
    "CIFAR_DIR = \"/home/herb/code/data/dataset/cf10data\"\n",
    "\n",
    "print(os.listdir(CIFAR_DIR))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "dict_keys([b'batch_label', b'labels', b'data', b'filenames'])\n"
     ]
    }
   ],
   "source": [
    "with open(os.path.join(CIFAR_DIR, \"data_batch_1\"),'rb') as f:\n",
    "    data1 = pickle.load(f,encoding='bytes')\n",
    "    print (data1.keys())\n",
    "    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<matplotlib.image.AxesImage at 0x7fbef1b57750>"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAPsAAAD5CAYAAADhukOtAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjEsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy8QZhcZAAAZ/klEQVR4nO2da4ycZ3XH/2dmZ3dt7ybeXccX1rfEcVEgQEK3FigVorRFKUIKlIvChygfIowqIhWJqopSqaRSP0BVQHyoqEwTEaqUEAiUqEpboogS+GKyMY7jxIE4xiTGxk58Yde3nZ2Z0w/zWtqE9/xn9p2byfP/Saudfc8873PmmffMzD7/OeeYu0MI8canNGgHhBD9QcEuRCIo2I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iKNiFSAQFuxCJoGAXIhEU7EIkgoJdiET4f7asgBza92XsAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "# 拿到第100张图片，\n",
    "image_arr = data1[b'data'][100]\n",
    "# 解析三通道\n",
    "image_arr = image_arr.reshape((3,32,32))\n",
    "# 转换RGB\n",
    "image_arr = image_arr.transpose((1,2,0))\n",
    "import matplotlib.pyplot as plt\n",
    "%matplotlib inline\n",
    "plt.imshow(image_arr)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
